<template>
  <div class="layout-all">
    <control :config="config" />
    <div class="layout-header" style="float: left;" />
    <div class="layout-content">
      <el-table
        :data="tableData"
        stripe
        align="center"
        highlight-current-row
        style="width: 100%; margin-top: 50px;"
      >
        <el-table-column align="center" prop="content" label="回答内容" />
        <el-table-column
          align="center"
          prop="user.nickname"
          label="用户"
          width="250"
        />
        <el-table-column
          align="center"
          prop="create_time"
          label="创建时间"
          width="250"
        />
        <el-table-column
          align="center"
          prop="update_time"
          label="修改时间"
          width="250"
        />
        <el-table-column
          align="center"
          prop="status"
          label="是否启用"
          width="80"
        >
          <template slot-scope="scope">
            <el-button
              :type="scope.row.status === 1 ? 'primary' : 'success'"
              size="mini"
              @click="change_status(scope.row.id, 'status', scope.row.status)"
              >{{ scope.row.status === 1 ? "是" : "否" }}</el-button
            >
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="telephone"
          fixed="right"
          width="240"
          label="操作"
        >
          <template slot-scope="scope">
            <!-- <router-link :to="'/ask_abt/answer/form?id=' + scope.row.id">
              <el-button type="primary" icon="el-icon-edit" />
            </router-link> -->
            <el-button
              size="small"
              type="danger"
              icon="el-icon-delete"
              @click="onDel(scope.row.id)"
            />
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      :current-page="current_page"
      :page-size="per_page"
      layout="total, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import control from "../../components/control/control";
export default {
  components: { control },
  data() {
    return {
      question_id: 0,
      config: [
        { type: "text", placeholder: "请输入内容", field: "content", val: "" },
      ],
      value: "",
      searchWhere: {
        title: "",
      },
      tableData: [],
      total: 0,
      current_page: 1,
      per_page: 14,
    };
  },
  mounted() {
    if (this.$route.query.id) {
      this.question_id = this.$route.query.id;
    }
    this.onSearch();
  },
  methods: {
    // 查询
    handleSizeChange(val) {
      this.onSearch();
    },
    handleCurrentChange(val) {
      this.current_page = val;
      this.onSearch();
    },
    onSearch() {
      const form = {};
      form.page = this.current_page;
      this.question_id === 0
        ? ""
        : (this.searchWhere.question_id = this.question_id);
      form.map = this.searchWhere;
      this.get("/admin/GoodsAnswer/index", form, "POST").then((e) => {
        this.tableData = e.list.data;
        this.per_page = e.list.per_page;
        this.total = e.list.total;
        this.current_page = e.list.current_page;
      });
    },
    // 添加
    onAdd() {},
    // 编辑
    onEdit(id) {
      console.log(id);
    },
    // 修改状态
    change_status(id, field, val) {
      this.update(id, val, field, "GoodsAnswer").then((e) => {
        e ? this.onSearch() : "";
      });
    },
    // 删除
    onDel(id) {
      this.$msg_confirm().then((e) => {
        if (e) {
          this.get("/admin/GoodsAnswer/del?id=" + id, this.form, "POST").then(
            (e) => {
              this.onSearch();
            }
          );
        }
      });
    },
  },
};
</script>

<style>
.layout-all {
  margin-top: 20px;
  margin-left: 10px;
}
.layout-content {
  margin-top: 20px;
}
</style>>
